package com.hyacinth.forumbite.interceptor;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: Yun
 * @Date: 2025/5/21
 */
@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns(("/**"))
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/register.html")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/logout")
                .excludePathPatterns("/dist/**")
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/**.ico")
                .excludePathPatterns("/js/**")
                // 放行 Knife4j 相关资源
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/v3*/**")
                .excludePathPatterns("/swagger*/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v3/**")
                .excludePathPatterns("/knife4j/**")
                .excludePathPatterns("/swagger-resources/**");
    }
}
